package com.ncloud.resman.mapper;

import com.ncloud.resman.entity.VirtualNetworkCard;
import org.apache.ibatis.annotations.*;

import java.util.List;

/**
 * Created by shiqiang on 2017/8/14.
 */
@Mapper
public interface VirtualNetworkCardMapper {
    @Insert("insert into res_virtual_network_card(card_id, virtual_id, card_name, card_ip, is_manage, state, create_user," +
            " create_date, update_user, update_date)"
            + " values(#{cardId},#{virtualId},#{cardName},#{cardIp},#{isManage},#{state},#{createUser},#{createDate},#{updateUser},#{updateDate})")
    int insertVirtualNetworkCard(VirtualNetworkCard virtualNetworkCard);
    @Update("update res_virtual_network_card set card_name = #{cardName},card_ip=#{cardIp},is_manage=#{isManage}," +
            " update_user=#{updateUser},update_date=#{updateDate} where state='1' and card_id =#{cardId}")
    int updateVirtualNetworkCard(VirtualNetworkCard virtualNetworkCard);

    @Select("SELECT card_id, virtual_id, card_name, card_ip, is_manage, state "
            + "FROM res_virtual_network_card where card_id = #{0} and state='1'")
    @Results({
            @Result(column="card_id",property="cardId"),@Result(column="virtual_id",property="virtualId"),
            @Result(column="card_name",property="cardName"),@Result(column="card_ip",property="cardIp"),
            @Result(column="is_manage",property="isManage"),@Result(column="state",property="state")})
    VirtualNetworkCard getVirtualNetworkCardById(Long cardId);//

    /*获取虚拟机的管理网ip*/
    @Select("SELECT card_id, virtual_id, card_name, card_ip, is_manage, state "
            + "FROM res_virtual_network_card where virtual_id = #{0} and state='1' and is_manage = '1'")
    @Results({
            @Result(column="card_id",property="cardId"),@Result(column="virtual_id",property="virtualId"),
            @Result(column="card_name",property="cardName"),@Result(column="card_ip",property="cardIp"),
            @Result(column="is_manage",property="isManage"),@Result(column="state",property="state")})
    List<VirtualNetworkCard> getVirtualManageIp(Long virtualId);//
    /*删除*/
    @Delete(value = "delete from res_virtual_network_card WHERE card_id =#{0}")
    int deleteVirtualNetworkCard(Long cardId);
    /*删除*/
    @Delete(value = "delete from res_virtual_network_card WHERE virtual_id = #{0}")
    int deleteVirtualCardByVirtualId(Long virtualId);
    @Update("update res_virtual_network_card set state= #{1} " +
            " where state='1' and card_id =#{0}")
    int updateVirtualNetworkCardState(Long cardId, String state);

    @Select("SELECT card_id, virtual_id, card_name, card_ip, is_manage, state "
            + "FROM res_virtual_network_card where virtual_id = #{0} and state='1'")
    @Results({
            @Result(column="card_id",property="cardId"),@Result(column="virtual_id",property="virtualId"),
            @Result(column="card_name",property="cardName"),@Result(column="card_ip",property="cardIp"),
            @Result(column="is_manage",property="isManage"),@Result(column="state",property="state")})
    List<VirtualNetworkCard> getVirtualNetworkVirtualId(Long virtualId);//


}
